// pages/person/list.js
var core = require('../../../utils/core.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 200,
    index:0,
    company_page:1,
    company:[],
    company_fresh:false,

    park_page:1,
    park:[],
    park_fresh:false,

    meeting_page:1,
    meeting:[],
    meeting_fresh:false,


    city_page:1,
    city:[],
    city_fresh:false,
  },
  changeIndicatorDots() {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },

  changeAutoplay() {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },

  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },

  durationChange(e) {
    this.setData({
      duration: e.detail.value
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     this.getCompanyList()
     this.getParkList()
     this.getMeetingList()
     this.getCityList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  more(){
   //我的企业
   if(this.data.index==0){
      this.getCompanyList()
   }
    //我的企业
    if(this.data.index==1){
      this.getParkList()
   }
   if(this.data.index==2){
    this.getMeetingList()
   }
   if(this.data.index==3){
    this.getCityList()
   }
},
onRefresh(){
  //我的企业
  if(this.data.index==0){
    this.setData({
      company_page:1,
      company:[],
      company_fresh:true
    })
     this.getCompanyList()
  }
  //我的园区
  if(this.data.index==1){
    this.setData({
      park_page:1,
      park:[],
      park_fresh:true
    })
     this.getParkList()
  }
  //我的会议
  if(this.data.index==2){
    this.setData({
      meeting_page:1,
      meeting:[],
      meeting_fresh:true,
    })
    this.getMeetingList()
  }
  //我的城市
  if(this.data.index==3){
    this.setData({
      city_page:1,
      city:[],
      city_fresh:true,
    })
    this.getCityList()
  }
},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //选项卡点击
  change:function(e){
    this.setData({index:e.target.id})
},
//触摸滑动
touch_change:function(e){
  // console.log(e)
  // return
  this.setData({index:e.detail.current})
},
/**
 * 企业list
 */
getCompanyList:function(){
  var self=this
  core.post("company",{page:self.data.company_page,op:'MyList'},function(res){
    if(res.code==1){   
        var current=self.data.company
        for(var i=0;i<res.data.length;i++){
          current.push(res.data[i])
        }
        self.setData({company:current,company_fresh:false,company_page:self.data.company_page+1})
    }
  })
},
/**
 * 园区list
 */
getParkList:function(){
  var self=this
  core.post("park",{page:self.data.park_page,op:'MyList'},function(res){
    if(res.code==1){ 
        var current=self.data.park
        for(var i=0;i<res.data.length;i++){
          current.push(res.data[i])
        }
        self.setData({park:current,park_fresh:false,park_page:self.data.park_page+1})
    }
  })
  
},
/**
 * 会议list
 */
getMeetingList:function(){
  var self=this
  core.post("meeting",{page:self.data.meeting_page,op:'MyCollectList'},function(res){
    if(res.code==1){     
        var current=self.data.meeting
        for(var i=0;i<res.data.length;i++){
          current.push(res.data[i])
        }
        self.setData({meeting:current,meeting_fresh:false,meeting_page:self.data.meeting_page+1})
    }
  }) 
},
/**
 * 城市list
 */
getCityList:function(){
  var self=this
  core.post("RecCity",{page:self.data.city_page,op:'MyList'},function(res){
    if(res.code==1){     
        var current=self.data.city
        for(var i=0;i<res.data.length;i++){
          current.push(res.data[i])
        }
        self.setData({city:current,city_fresh:false,city_page:self.data.city_page+1})
    }
  }) 
},
/**
 * 企业删除
 */
CompanyCancleCollect:function(target){
  var targetData=target.target.id.split('&') 
  var identification=targetData[0]
  var index=targetData[1]
  var self=this
  wx.showModal({
    title: '提示',
    content: '确定取消收藏吗？',
    success: function (res) {
      if(res.confirm){
        core.post("company",{identification:identification,op:'collect'},function(res){
          if(res.code==1){
              var current=self.data.company
              current.splice(index*1,1)
              self.setData({company:current})
          }
        })
      }
    }
  })
},
/**
 * 园区删除
 */
ParkCancleCollect:function(target){
  var targetData=target.target.id.split('&') 
  var identification=targetData[0]
  var index=targetData[1]
  var self=this
  wx.showModal({
    title: '提示',
    content: '确定取消收藏吗？',
    success: function (res) {
      if(res.confirm){
        core.post("park",{identification:identification,op:'collect'},function(res){
          if(res.code==1){
              var current=self.data.park
              current.splice(index*1,1)
              self.setData({park:current})
          }
        })
      }
    }
  })
},
/**
 * 会议删除
 */
MeetingCancleCollect:function(target){
  var targetData=target.target.id.split('&') 
  var id=targetData[0]
  var index=targetData[1]
  var self=this
  wx.showModal({
    title: '提示',
    content: '确定取消收藏吗？',
    success: function (res) {
      if(res.confirm){
        core.post("meeting",{id:id,op:'collect'},function(res){
          if(res.code==1){
              var current=self.data.meeting
              current.splice(index*1,1)
              self.setData({meeting:current})
          }
        })
      }
    }
  })
},
/**
 * 城市删除
 */
CityCancleCollect:function(target){
  var targetData=target.target.id.split('&') 
  var id=targetData[0]
  var index=targetData[1]
  var self=this
  wx.showModal({
    title: '提示',
    content: '确定取消收藏吗？',
    success: function (res) {
      if(res.confirm){
        core.post("RecCity",{id:id,op:'collect'},function(res){
          if(res.code==1){
              var current=self.data.city
              current.splice(index*1,1)
              self.setData({city:current})
          }
        })
      }
    }
  })
},
})